package com.itheima.controller;

import com.itheima.admin.dishpojo.Dish;
import com.itheima.common.JsonResult;
import com.itheima.service.ClientDishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author wuzhiyong
 */
@RestController
@RequestMapping(value = "/dish")
public class ClientDishController {
    @Autowired
    private ClientDishService clientDishService;

    /**
     * 菜品列表
     *
     * @param categoryId categoryId
     * @param status     status
     * @return List<Dish>
     */
    @GetMapping(value = "list")
    public JsonResult<List<Dish>> dishList(@RequestParam(value = "categoryId") String categoryId, @RequestParam(value = "status") Integer status) {
        List<Dish> dishes = clientDishService.getByCategoryIdAndStatus(categoryId, status);
        if (dishes != null) {
            return JsonResult.success(dishes, null);
        }
        return JsonResult.error("暂无商品在售");
    }
}
